﻿namespace imichaelmiers.wp7.security.cryptography.PasswordProtectedStorage
{
    using System;
    using System.Security.Cryptography;

    /// <summary>
    /// Wrapper class for Symmetric Cipher. Dispose does not necessarily 
    /// call clear for SymmetricAlgorithms. Most of the .net crypto algorithms 
    /// do, but this  is by convention and not contract and so this ensures 
    /// clear is called.
    /// </summary>
    internal class SymmetricAlgorithmWrapper : IDisposable
    {
        public readonly SymmetricAlgorithm Cipher;

        /// <summary>
        /// Wraps the supplied SymmetricAlgorithm.
        /// </summary>
        /// <param name="cipher">The SymmetricAlgorithm to wrap.</param>
        public SymmetricAlgorithmWrapper(SymmetricAlgorithm cipher)
        {
            this.Cipher = cipher;
        }

        public void Dispose()
        {
            // this is supposed to be disposable in Silverlight, 
            // but apparently not so all we can do is clear 
            this.Cipher.Clear();
        }
    }
}
